//
//  HamatonCarTyreViewController.swift
//  hamaton-app
//
//  Created by intyt on 2024/4/16.
// 车辆轮位设置

import UIKit
import CoreBluetooth
import SnapKit
import Toast_Swift


class HamatonCarTyreViewController: HamatonBaseViewController {
    var carType: String = "0"
    var carTyreModel: CarTyreModel = CarTyreModel()
    // 车辆轮胎传感器绑定
    var TyreTmpsBaudRateModel: TyreTmps? {
        didSet {
            var color = Theme.Color.Background.tyregray
            if TyreTmpsBaudRateModel?.isBind == true {
                color = Theme.Color.Background.main
            } else {
                color = Theme.Color.Background.tyregray
            }
            let isBind = TyreTmpsBaudRateModel?.isBind
            if TyreTmpsBaudRateModel?.tyreNum == "16" {
                tyreBtn16.backgroundColor = color
                carTyreModel.tyre16 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "17" {
                tyreBtn17.backgroundColor = color
                carTyreModel.tyre17 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "19" {
                tyreBtn19.backgroundColor = color
                carTyreModel.tyre19 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "1A" {
                tyreBtn1a.backgroundColor = color
                carTyreModel.tyre1a = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "26" {
                tyreBtn26.backgroundColor = color
                carTyreModel.tyre26 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "27" {
                tyreBtn27.backgroundColor = color
                carTyreModel.tyre27 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "29" {
                tyreBtn29.backgroundColor = color
                carTyreModel.tyre29 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "2A" {
                tyreBtn2a.backgroundColor = color
                carTyreModel.tyre2a = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "36" {
                tyreBtn36.backgroundColor = color
                carTyreModel.tyre36 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "37" {
                tyreBtn37.backgroundColor = color
                carTyreModel.tyre37 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "39" {
                tyreBtn39.backgroundColor = color
                carTyreModel.tyre39 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "3A" {
                tyreBtn3a.backgroundColor = color
                carTyreModel.tyre3a = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "46" {
                tyreBtn46.backgroundColor = color
                carTyreModel.tyre46 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "47" {
                tyreBtn47.backgroundColor = color
                carTyreModel.tyre47 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "49" {
                tyreBtn49.backgroundColor = color
                carTyreModel.tyre49 = isBind!
            } else if TyreTmpsBaudRateModel?.tyreNum == "4A" {
                tyreBtn4a.backgroundColor = color
                carTyreModel.tyre4a = isBind!
            }
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .clear
        navigationItem.title = "轮胎参数设置"
        let margTop: Float = 15
        let margRight: Float = -20
        let margLeft: Float = 20
        print(carType)
        print(789)
        view.addSubview(centerLine) // 中心线
        view.addSubview(tyreBtn17) // 一轴左内胎
        view.addSubview(tyreBtn16) // 一轴左外胎
        view.addSubview(tyreBtn19) // 一轴右内胎
        view.addSubview(tyreBtn1a) // 一轴右外胎
        view.addSubview(tyreBtn27) // 二轴左内胎
        view.addSubview(tyreBtn26) // 二轴左外胎
        view.addSubview(tyreBtn29) // 二轴右内胎
        view.addSubview(tyreBtn2a) // 二轴右外胎
        view.addSubview(tyreBtn37) // 三轴左内胎
        view.addSubview(tyreBtn36) // 三轴左外胎
        view.addSubview(tyreBtn39) // 三轴右内胎
        view.addSubview(tyreBtn3a) // 三轴右外胎
        view.addSubview(tyreBtn47) // 四轴左内胎
        view.addSubview(tyreBtn46) // 四轴左外胎
        view.addSubview(tyreBtn49) // 四轴右内胎
        view.addSubview(tyreBtn4a) // 四轴右外胎
        view.addSubview(thresholdSettingBtn) // 阈值设置按钮
//
        if carType == "0" {
            tyreBtn16.isHidden = true
            tyreBtn1a.isHidden = true
        }
        // 中心线
        centerLine.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop)
            // x轴居中对齐
            make.centerX.equalToSuperview()
            make.width.equalTo(1)
            make.height.equalTo(560)
        }
        // 一轴左内胎
        tyreBtn17.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop*4)
            make.right.equalTo(centerLine.snp.left).offset(margRight*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 一轴左外胎
        tyreBtn16.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop*4)
            make.right.equalTo(tyreBtn17.snp.left).offset(margRight)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 一轴右内胎
        tyreBtn19.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop*4)
            make.left.equalTo(centerLine.snp.right).offset(margLeft*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 一轴右外胎
        tyreBtn1a.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(margTop*4)
            make.left.equalTo(tyreBtn19.snp.right).offset(margLeft)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 二轴左内胎
        tyreBtn27.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn17.snp.bottom).offset(margTop)
            make.right.equalTo(centerLine.snp.left).offset(margRight*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 二轴左外胎
        tyreBtn26.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn16.snp.bottom).offset(margTop)
            make.right.equalTo(tyreBtn17.snp.left).offset(margRight)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 二轴右内胎
        tyreBtn29.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn19.snp.bottom).offset(margTop)
            make.left.equalTo(centerLine.snp.right).offset(margLeft*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 二轴右外胎
        tyreBtn2a.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn1a.snp.bottom).offset(margTop)
            make.left.equalTo(tyreBtn19.snp.right).offset(margLeft)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 三轴左内胎
        tyreBtn37.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn27.snp.bottom).offset(margTop)
            make.right.equalTo(centerLine.snp.left).offset(margRight*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 三轴左外胎
        tyreBtn36.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn26.snp.bottom).offset(margTop)
            make.right.equalTo(tyreBtn27.snp.left).offset(margRight)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 三轴右内胎
        tyreBtn39.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn29.snp.bottom).offset(margTop)
            make.left.equalTo(centerLine.snp.right).offset(margLeft*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 三轴右外胎
        tyreBtn3a.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn2a.snp.bottom).offset(margTop)
            make.left.equalTo(tyreBtn29.snp.right).offset(margLeft)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 四轴左内胎
        tyreBtn47.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn37.snp.bottom).offset(margTop)
            make.right.equalTo(centerLine.snp.left).offset(margRight*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 四轴左外胎
        tyreBtn46.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn36.snp.bottom).offset(margTop)
            make.right.equalTo(tyreBtn37.snp.left).offset(margRight)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 四轴右内胎
        tyreBtn49.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn39.snp.bottom).offset(margTop)
            make.left.equalTo(centerLine.snp.right).offset(margLeft*2)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 四轴右外胎
        tyreBtn4a.snp.makeConstraints { make in
            make.top.equalTo(tyreBtn3a.snp.bottom).offset(margTop)
            make.left.equalTo(tyreBtn39.snp.right).offset(margLeft)
            make.width.equalTo(50)
            make.height.equalTo(100)
        }
        // 阈值设置按钮
        thresholdSettingBtn.snp.makeConstraints { make in
            make.top.equalTo(centerLine.snp.bottom).offset(margTop)
            make.left.equalToSuperview().offset(26)
            make.right.equalToSuperview().offset(-26)
            make.height.equalTo(40)
        }

    }
    
    
    // 中心线
    lazy var centerLine: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.backgroundColor  = Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 一轴左外胎：轮胎1，6
    lazy var tyreBtn16: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre16 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 一轴左内胎：轮胎1，7
    lazy var tyreBtn17: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre17 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 一轴右内胎：轮胎1，9
    lazy var tyreBtn19: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre19 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 一轴右外胎：轮胎1，a
    lazy var tyreBtn1a: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre1a ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 二轴左外胎：轮胎2，6
    lazy var tyreBtn26: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre26 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 二轴左内胎：轮胎2，7
    lazy var tyreBtn27: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre27 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 二轴右内胎：轮胎2，9
    lazy var tyreBtn29: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre29 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 二轴右外胎：轮胎2，a
    lazy var tyreBtn2a: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre2a ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 三轴左外胎：轮胎3，6
    lazy var tyreBtn36: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre36 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 三轴左内胎：轮胎3，7
    lazy var tyreBtn37: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre37 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 三轴右内胎：轮胎3，9
    lazy var tyreBtn39: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre39 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 三轴右外胎：轮胎3，a
    lazy var tyreBtn3a: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre3a ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 四轴左外胎：轮胎4，6
    lazy var tyreBtn46: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre46 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 四轴左内胎：轮胎4，7
    lazy var tyreBtn47: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre47 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 四轴右内胎：轮胎4，9
    lazy var tyreBtn49: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre49 ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 四轴右外胎：轮胎4，a
    lazy var tyreBtn4a: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickTyreButton(tf:)), for: .touchUpInside)
        button.backgroundColor  = carTyreModel.tyre4a ? Theme.Color.Background.main : Theme.Color.Background.tyregray
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 阈值设置按钮
    lazy var thresholdSettingBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitle(NSLocalizedString("阈值设置", tableName: "HamatonLocalizable", comment: ""), for: .normal)
        button.setTitleColor(UIColor(hex6: 0xFFFFFF, alpha: 1.0), for: .normal)
        button.titleLabel!.font = Theme.Font.size(16, bold: true)
        button.addTarget(self, action: #selector(onClickThresholdSettingButton), for: .touchUpInside)
        button.backgroundColor  = Theme.Color.Background.main
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 5
        return button
    }()
    // 阈值设置按钮
    @objc func onClickThresholdSettingButton() {
        print("阈值设置")
        let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
        vc?.navigateToThresholdSettingView()
    }
    
    // 轮位传感器设置
    @objc func onClickTyreButton(tf: UIButton) {
        if tf == tyreBtn16 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("16", carTyreModel.tyre16)
        } else if tf == tyreBtn17 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("17", carTyreModel.tyre17)
        } else if tf == tyreBtn19 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("19", carTyreModel.tyre19)
        } else if tf == tyreBtn1a {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("1A", carTyreModel.tyre1a)
        } else if tf == tyreBtn26 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("26", carTyreModel.tyre26)
        } else if tf == tyreBtn27 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("27", carTyreModel.tyre27)
        } else if tf == tyreBtn29 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("29", carTyreModel.tyre29)
        } else if tf == tyreBtn2a {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("2A", carTyreModel.tyre2a)
        } else if tf == tyreBtn36 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("36", carTyreModel.tyre36)
        } else if tf == tyreBtn37 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("37", carTyreModel.tyre37)
        } else if tf == tyreBtn39 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("39", carTyreModel.tyre39)
        } else if tf == tyreBtn3a {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("3A", carTyreModel.tyre3a)
        } else if tf == tyreBtn46 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("46", carTyreModel.tyre46)
        } else if tf == tyreBtn47 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("47", carTyreModel.tyre47)
        } else if tf == tyreBtn49 {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("49", carTyreModel.tyre49)
        } else if tf == tyreBtn4a {
            let vc = navigationController?.viewControllers.first(where: { $0 is HamatonDeviceViewController }) as? HamatonDeviceViewController
            vc?.navigateToWheelSensorView("4A", carTyreModel.tyre4a)
        }
        
        
    }
    
    // 获取轮胎位号
    func getTyrePosition() {
        // 查询所有轮胎位号
//        print(self.hamatonBluethoothInfo.connectedPeripheral)
//        let byte:[UInt8] = [0x34]
//        let data = Data(bytes: byte, count: 1)
//        print("获取所有轮胎位号")
//        self.hamatonBluethoothInfo.connectedPeripheral!.writeValue(data, for: self.hamatonBluethoothInfo.characteristic!, type: CBCharacteristicWriteType.withResponse)
    }

    // 页面刷新 type:1擦除 2绑定
    func refreshData(_ tyreStr: String, _ type: Int) {
        print("调用刷新页面了")
        if type == 1 {
            self.TyreTmpsBaudRateModel = TyreTmps(tyreNum: tyreStr, isBind: false)
            self.view.makeToast("轮胎擦除成功", duration: 3.0, position: .center)
        } else {
            self.TyreTmpsBaudRateModel = TyreTmps(tyreNum: tyreStr, isBind: true)
            self.view.makeToast("传感器绑定成功", duration: 3.0, position: .center)
        }
    }
    // 阈值设置成功
    func thresholdSettingSuccess() {
        self.view.makeToast("阈值设置成功", duration: 3.0, position: .center)
    }
    
}

